import java.io.*;

class ConsoleReaderUtility {

	private static final double DEFAULT_VALUE = 10;
	private static final String CANNOT_READ_INT = 
				"Can't read value. Default one will be used. ("+((int)DEFAULT_VALUE)+")";
	private static final String CANNOT_READ_DOUBLE = 
				"Can't read value. Default one will be used. ("+DEFAULT_VALUE+")";
	private static final String NOT_A_NUMBER = 
				"Not a number. Default value will be used. ("+DEFAULT_VALUE+")";
	private static final String ERROR_TRYING_TO_CLOSE_A_READER = 
				"Error occured while trying to close a reader";
	
	public int readInteger(String consoleMessage){
		int result;
		System.out.println(consoleMessage);
		BufferedReader br = new BufferedReader(
								new InputStreamReader(
									System.in));
		try{
			result = Integer.parseInt(br.readLine());
		} catch (IOException e) {
			result = ((int)DEFAULT_VALUE);
			System.out.println(CANNOT_READ_INT);
		} catch (NumberFormatException e) {
			result = ((int)DEFAULT_VALUE);
			System.out.println(NOT_A_NUMBER);
		}
		
		return result;
	}
	
	public double readDouble(String consoleMessage){
		double result;
		System.out.println(consoleMessage);
		BufferedReader br = new BufferedReader(
								new InputStreamReader(
									System.in));
		try{
			result = Double.parseDouble(br.readLine());
		} catch (IOException e) {
			result = DEFAULT_VALUE;
			System.out.println(CANNOT_READ_DOUBLE);
		} catch (NumberFormatException e) {
			result = DEFAULT_VALUE;
			System.out.println(NOT_A_NUMBER);
		}
		
		return result;
	}
	
	public int[] readIntegerArray(String consoleMessage) 
								throws IOException{
		int[] result;
		
		String line = readString(consoleMessage);
		
		if (!line.equals("")) { 
		
			String[] enteredValues = line.split(" ");
			
			result = new int[enteredValues.length];
			
			int index = 0;
			for (String currentElement: enteredValues){
				try{
					result[index++]=Integer.parseInt(currentElement);
				} catch (NumberFormatException e){
					result[--index]=(int) DEFAULT_VALUE;
					index++;
					System.out.println(currentElement+" is not an integer. Default value ("+
										((int)DEFAULT_VALUE)+") will be used");
				}
			}
		} else {
			result = new int[0];
		}
		
		return result;
	}
	
	public String readString(String consoleMessage) 
								throws IOException{
		String result = null;
		System.out.println(consoleMessage);
		BufferedReader br = new BufferedReader(
								new InputStreamReader(
									System.in));
		
		return br.readLine();
	}

}